package com.graduation.mybatis.controller;

import com.graduation.mybatis.bean.CoachRecommendations;
import com.graduation.mybatis.bean.DietPlans;
import com.graduation.mybatis.service.CoachRecommendationsService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * (CoachRecommendations)表控制层
 *
 * @author makejava
 * @since 2025-04-22 12:00:35
 */
@RestController
@RequestMapping("coachRecommendations")
public class CoachRecommendationsController {
    /**
     * 服务对象
     */
    @Resource
    private CoachRecommendationsService coachRecommendationsService;

    /**
     * 分页查询
     *
     * @param coachRecommendations 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
//    @GetMapping
//    public ResponseEntity<Page<CoachRecommendations>> queryByPage(CoachRecommendations coachRecommendations, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.coachRecommendationsService.queryByPage(coachRecommendations, pageRequest));
//    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CoachRecommendations> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.coachRecommendationsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param coachRecommendations 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CoachRecommendations> add(CoachRecommendations coachRecommendations) {
        return coachRecommendationsService.save(coachRecommendations) ?
                ResponseEntity.ok(coachRecommendations) :
                ResponseEntity.internalServerError().build();
    }

    /**
     * 编辑数据
     *
     * @param coachRecommendations 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CoachRecommendations> edit(CoachRecommendations coachRecommendations) {
        return coachRecommendationsService.updateById(coachRecommendations) ?
                ResponseEntity.ok(coachRecommendations) :
                ResponseEntity.internalServerError().build();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.coachRecommendationsService.removeById(id));
    }

    /**
     * 获取所有推荐方案
     *
     * @return 所有推荐方案
     */
    @GetMapping
    public ResponseEntity<Map<String, Object>> getCoachRecommendations() {
        List<CoachRecommendations> recommendations = coachRecommendationsService.getAllCoachRecommendations();
        Map<String, Object> response = new HashMap<>();
        response.put("data", Map.of(
                "success", true,
                "message", "获取成功",
                "data", recommendations
        ));
        return ResponseEntity.ok(response);
    }
}

